<?php
/**
 * RedXenon Framework
 * 
 * LICENSE
 * 
 * This source file is subject to the New BSD license that is bundled
 * with this package in the file LICENSE.txt
 * A copy of this license can be found in the world-wide-web at this URL:
 * http://www.redxenon.com/license/new-bsd-license.txt
 */

/** Abstract class */
require_once "RXLogManager.php";

/** 
 * RedXenon LogManager (RXLogManagerTXT.php)
 * Class to manage log files in text mode
 * 
 * @category RedXenon
 * @package RedXenon_Log
 * @copyright Copyright (c) 2011 Red Xenon (http://www.redxenon.com)
 * @version $Id: RXLogManagerTXT.php 1.0 2011-04-22 $ 
 */
class RXLogManagerTXT extends RXLogManager{

	/**
	 * @param $filePath
	 */
	function __construct($filePath, $maxFileSize){
		$this->filePath = $filePath;
		$this->maxSize = $maxFileSize;
	}
	
	/**
	 * Writes a message in a log file
	 * @param String $message
	 * @param Integer $priority
	 * @param String $file
	 * @param Integer $line
	 */
	function write($message, $priority, $file = null, $line = null){
		try{
			if(!$this->logHandler){
				self::open();
			}
		}catch(Exception $e){
			echo $e->getMessage();	
		}
		
		if($this->logHandler){
			$content = date(DATE_RFC1123)." - PRIORITY: ".$priority."\n".$message;
			
			if($file){
				$content .= "\n\tFILE: ".$file;
			}
			
			if($line){
				$content .= "\n\tLINE: ".$line;
			}
			
			$content .= "\n";
			
			@fwrite($this->logHandler, $content);
			self::close();
		}
	}
}
?>